clipboard: Add surface apis
authorMatthias Clasen <mclasen@redhat.com>
Sun, 22 Oct 2017 20:17:43 +0000 (22:17 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 22 Oct 2017 20:22:31 +0000 (22:22 +0200)
Add gtk_clipboard_set_surface and gtk_clipboard_wait_for_surface.

gtk/gtkclipboard.c
gtk/gtkclipboard.h

index 329299ea7a6b3976be2321c127a1e4735a51066f..496e44cf8604be5c8ac9415542111dcf49eb839e 100644 (file)
@@ -930,6 +930,21 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
   gtk_target_list_unref (list);
 }
 
+void
+gtk_clipboard_set_surface (GtkClipboard    *clipboard,
+                           cairo_surface_t *surface)
+{
+  GdkPixbuf *pixbuf;
+
+  pixbuf = gdk_pixbuf_get_from_surface (surface,
+                                        0, 0,
+                                        cairo_image_surface_get_width (surface),
+                                        cairo_image_surface_get_height (surface));
+  gtk_clipboard_set_image (clipboard, pixbuf);
+  g_object_unref (pixbuf);
+
+}
+
 static void
 set_request_contents_info (GtkWidget           *widget,
                           RequestContentsInfo *info)
@@ -1579,6 +1594,19 @@ clipboard_image_received_func (GtkClipboard *clipboard,
   g_main_loop_quit (results->loop);
 }
 
+static void
+clipboard_surface_received_func (GtkClipboard *clipboard,
+                                 GdkPixbuf    *pixbuf,
+                                gpointer      data)
+{
+  WaitResults *results = data;
+
+  if (pixbuf)
+    results->data = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
+
+  g_main_loop_quit (results->loop);
+}
+
 /**
  * gtk_clipboard_wait_for_image:
  * @clipboard: a #GtkClipboard
@@ -1623,6 +1651,31 @@ gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
   return results.data;
 }
 
+cairo_surface_t *
+gtk_clipboard_wait_for_surface (GtkClipboard *clipboard)
+{
+  WaitResults results;
+
+  g_return_val_if_fail (clipboard != NULL, NULL);
+  
+  results.data = NULL;
+  results.loop = g_main_loop_new (NULL, TRUE);
+
+  gtk_clipboard_request_image (clipboard,
+                              clipboard_surface_received_func,
+                              &results);
+
+  if (g_main_loop_is_running (results.loop))
+    {
+      gdk_threads_leave ();
+      g_main_loop_run (results.loop);
+      gdk_threads_enter ();
+    }
+
+  g_main_loop_unref (results.loop);
+
+  return results.data;
+}
 static void 
 clipboard_uris_received_func (GtkClipboard *clipboard,
                              gchar       **uris,
index 655c18fcda4e78ab6fe9f5b6009d55d405512598..68a68a622911743516750363cb3e01390f986ae8 100644 (file)
@@ -221,6 +221,9 @@ void     gtk_clipboard_set_text       (GtkClipboard          *clipboard,
 GDK_AVAILABLE_IN_ALL
 void     gtk_clipboard_set_image      (GtkClipboard          *clipboard,
                                       GdkPixbuf             *pixbuf);
+GDK_AVAILABLE_IN_3_94
+void     gtk_clipboard_set_surface    (GtkClipboard    *clipboard,
+                                       cairo_surface_t *surface);
 
 GDK_AVAILABLE_IN_ALL
 void gtk_clipboard_request_contents  (GtkClipboard                     *clipboard,
@@ -268,6 +271,8 @@ gboolean          gtk_clipboard_wait_for_targets   (GtkClipboard  *clipboard,
                                                     GdkAtom      **targets,
                                                     gint          *n_targets);
 
+GDK_AVAILABLE_IN_3_94
+cairo_surface_t * gtk_clipboard_wait_for_surface   (GtkClipboard  *clipboard);
 GDK_AVAILABLE_IN_ALL
 gboolean gtk_clipboard_wait_is_text_available      (GtkClipboard  *clipboard);
 GDK_AVAILABLE_IN_ALL